package vcp.gui.guest.screens;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;

import javax.swing.JPanel;

import vcp.gui.components.VCPFrame;
import vcp.gui.components.VCPPanel;
import vcp.gui.forms.OrderOccasionalForm;
import vcp.gui.forms.OrderSubscriptionForm;
import vcp.gui.forms.OrderTemporaryForm;

import javax.swing.ButtonGroup;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JRadioButton;
import javax.swing.LayoutStyle.ComponentPlacement;

import control.SimpleClient;

public class ScreenOrders extends VCPPanel implements ActionListener {
	private JRadioButton occasionalButton;
	private JRadioButton SubscriptionButton;
	private JRadioButton PreOrderButton;
    private VCPPanel buttonPanel;
    private VCPPanel formPanel;
    
    /* switched forms */
    private OrderSubscriptionForm orderSubscriptionForm;
    private OrderTemporaryForm orderTemporaryForm;
    private OrderOccasionalForm orderOccasionalForm;
    
    
	private SimpleClient client;
	/**
	 * Create the panel.
	 * @param client 
	 */
	public ScreenOrders(SimpleClient client) {
		this.client = client;
		buttonPanel = new VCPPanel(new GridLayout(1, 1));
		
		orderSubscriptionForm = new OrderSubscriptionForm(client);
		orderOccasionalForm = new OrderOccasionalForm(client);
		orderTemporaryForm = new OrderTemporaryForm(client);
		buildRadioPanel();
		formPanel = new VCPPanel();
		formPanel.add(orderOccasionalForm);
		GroupLayout groupLayout = new GroupLayout(this);
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addComponent(buttonPanel, GroupLayout.DEFAULT_SIZE, 450, Short.MAX_VALUE)
				.addComponent(formPanel, GroupLayout.DEFAULT_SIZE, 450, Short.MAX_VALUE)
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addComponent(buttonPanel, GroupLayout.PREFERRED_SIZE, 52, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(formPanel, GroupLayout.DEFAULT_SIZE, 241, Short.MAX_VALUE))
		);
		setLayout(groupLayout);
		
	}
	
	private void buildRadioPanel() {

		occasionalButton = new JRadioButton("Occasional");
		occasionalButton.setMnemonic(KeyEvent.VK_R);
		occasionalButton.setActionCommand("OO");
		occasionalButton.setSelected(true);

		SubscriptionButton = new JRadioButton("Subscription");
		SubscriptionButton.setMnemonic(KeyEvent.VK_S);
		SubscriptionButton.setActionCommand("OS");
		SubscriptionButton.setSelected(false);

		PreOrderButton = new JRadioButton("Temporary");
		PreOrderButton.setMnemonic(KeyEvent.VK_P);
		PreOrderButton.setActionCommand("OT");
		PreOrderButton.setSelected(false);

		occasionalButton.addActionListener(this);
		SubscriptionButton.addActionListener(this);
		PreOrderButton.addActionListener(this);

		ButtonGroup btngroup = new ButtonGroup();
		btngroup.add(occasionalButton);
		btngroup.add(SubscriptionButton);
		btngroup.add(PreOrderButton);


		buttonPanel.add(occasionalButton);
		buttonPanel.add(SubscriptionButton);
		buttonPanel.add(PreOrderButton); //		
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		if ((e.getActionCommand()).equals("OO")){
			formPanel.loadPanel(orderOccasionalForm);			
		} else if ((e.getActionCommand()).equals("OT")) {			
			formPanel.loadPanel(orderTemporaryForm);
		} else if ((e.getActionCommand()).equals("OS")) {			
			formPanel.loadPanel(orderSubscriptionForm);
		}
	}
	
	
	
}
